home *** CD-ROM | disk | FTP | other *** search
- Path: news.ichange.com!newsmaster
- From: Jesse Liberty <jl@staff.ichange.com>
- Newsgroups: comp.lang.c++
- Subject: Re: No struct in C++!!?
- Date: Thu, 15 Feb 1996 07:53:32 -0500
- Organization: AT&T
- Message-ID: <31232CCC.4679@staff.ichange.com>
- References: <1996Feb14.151620.5532@queens-belfast.ac.uk>
- NNTP-Posting-Host: 140.244.99.60
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (Win95; I)
- CC: jl@staff.ichange.com
-
- Georg Woste wrote:
- >
- > I found in different C++ books examples of C++ programms
- > which contain type declarations and definitions in the main() programm - for
- > example a struct - as in C.
- > My question is, whether this is a contradiction
- > to the paradigm of C++.
-
- In C++ a struct is EXACTLY like a class in every aspect (can have members and functions) except that the default inheritance
- is public (not private) and the default access for members is public (not private). Thus the distinction you are making
- between a data only object and an object with methods is specious -- both structs and classes can be any of data-only,
- method-only or both.
-
- By convention, some C++ programmers use "struct" for data-only objects, but this is somewhat misleading; there is no reason
- you can't write
-
- struct Animal
- {
- int myAge;
- void SetAge(int age) { myAge = age); }
- };
-
- In fact, if you explicitly use access specifiers (as I believe you should) you won't see ANY difference at all.
-
- By the way, I cover this in detail on page 151 of Teach Yourself C++ In 21 Days. :-)
-
- --
- Jesse Liberty jl@staff.ichange.com
- AT&T CIS: 72241,72
-